Arrays and For Loop [closed]

Posted by java on Programmers See other posts from Programmers or by java
Published on 2012-08-31T19:58:00Z Indexed on 2012/08/31 21:48 UTC
Read the original article Hit count: 71

Filed under:
|

I wrote this code:

import java.io.*;
public class dictionary 
{    
    public static void main(String args[])
    {
        String[] MyArrayE=new String[5];
        String[] MyArrayS=new String[5];
        String[] MyArrayA=new String[5];

        MyArrayE[0]="Language";
        MyArrayE[1]="Computer";
        MyArrayE[2]="Engineer";
        MyArrayE[3]="Home";
        MyArrayE[4]="Table";


        MyArrayS[0]="Lingua";
        MyArrayS[1]="Computador";
        MyArrayS[2]="Ing.";
        MyArrayS[3]="Casa";
        MyArrayS[4]="Mesa";

            System.out.println("Please enter a word");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
          String word= null;
           try {
             word= br.readLine();
           } catch (IOException e) {
             System.out.println("Error!");
             System.exit(1);
           }
           System.out.println("Your word is " + word);


        for(int i=0; i<MyArrayA.length; i++)  
        {
            if(word.equals(MyArrayS[i]))
            {
                System.out.println(MyArrayE[i]);

            }
        }   

    }
}

My Question: What about if the user inputs a word not in MyArrayS, I want to check that and print a statement like "Word does not exist".

I think that it might look like:

if(word!=MyArrayS)
{
System.out.println("Word does not exist");
}

© Programmers or respective owner

Related posts about array

Related posts about dictionary